test added

Judy Ngai 9 年之前
父节点
当前提交
11480bbb7b
共有 1 个文件被更改,包括 21 次插入0 次删除
  1. 21 0
      spec/models/agents/email_digest_agent_spec.rb

+ 21 - 0
spec/models/agents/email_digest_agent_spec.rb

@@ -11,6 +11,10 @@ describe Agents::EmailDigestAgent do
11 11
     @checker = Agents::EmailDigestAgent.new(:name => "something", :options => { :expected_receive_period_in_days => "2", :subject => "something interesting" })
12 12
     @checker.user = users(:bob)
13 13
     @checker.save!
14
+
15
+    @checker1 = Agents::EmailDigestAgent.new(:name => "something", :options => { :expected_receive_period_in_days => "2", :subject => "something interesting", :content_type => "text/plain" })
16
+    @checker1.user = users(:bob)
17
+    @checker1.save!
14 18
   end
15 19
 
16 20
   after do
@@ -35,6 +39,7 @@ describe Agents::EmailDigestAgent do
35 39
   end
36 40
 
37 41
   describe "#check" do
42
+
38 43
     it "should send an email" do
39 44
       Agents::EmailDigestAgent.async_check(@checker.id)
40 45
       expect(ActionMailer::Base.deliveries).to eq([])
@@ -47,6 +52,7 @@ describe Agents::EmailDigestAgent do
47 52
       @checker.save!
48 53
 
49 54
       Agents::EmailDigestAgent.async_check(@checker.id)
55
+
50 56
       expect(ActionMailer::Base.deliveries.last.to).to eq(["bob@example.com"])
51 57
       expect(ActionMailer::Base.deliveries.last.subject).to eq("something interesting")
52 58
       expect(get_message_part(ActionMailer::Base.deliveries.last, /plain/).strip).to eq("Event\n  data: Something you should know about\n\nFoo\n  bar: 2\n  url: http://google.com\n\nhi\n  woah: there\n\nEvent\n  test: 2")
@@ -73,5 +79,20 @@ describe Agents::EmailDigestAgent do
73 79
 
74 80
       expect(@checker.reload.memory[:queue]).to be_empty
75 81
     end
82
+    
83
+    it "should send email with correct content type" do
84
+      Agents::EmailDigestAgent.async_check(@checker1.id)
85
+      expect(ActionMailer::Base.deliveries).to eq([])
86
+
87
+      @checker1.memory[:queue] = [{ :data => "Something you should know about" },
88
+                                 { :title => "Foo", :url => "http://google.com", :bar => 2 },
89
+                                 { "message" => "hi", :woah => "there" },
90
+                                 { "test" => 2 }]
91
+      @checker1.memory[:events] = [1,2,3,4]
92
+      @checker1.save!
93
+
94
+      Agents::EmailDigestAgent.async_check(@checker1.id)
95
+      expect(ActionMailer::Base.deliveries.last.content_type).to eq("text/plain; charset=UTF-8")
96
+    end
76 97
   end
77 98
 end